package yxy.game.pm2.command.tower;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.TowerMessage;
import yxy.game.pm2.module.tower.TowerHandle;

/** 修炼塔 目标奖励领取 */
@MessageType(proto = Command.TowerBonusReceive, classtype = TowerMessage.TowerBonusReceiveRequest.class)
public class CMD_TowerBonusReceive extends Command<TowerMessage.TowerBonusReceiveRequest> {

	@Override
	public void execute(MessageSource messageSource, TowerMessage.TowerBonusReceiveRequest request) {
		String playerCode = messageSource.getTag();
		int box = request.getBox();

		TowerMessage.TowerBonusReceiveResponse.Builder response = TowerMessage.TowerBonusReceiveResponse.newBuilder();

		Result result = new TowerHandle().levelReward(playerCode, box, response);

		send(messageSource, response, result);
	}

	private void send(MessageSource messageSource, TowerMessage.TowerBonusReceiveResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}